namespace 项目01;

class Students
{
    public string name;
    public string id;
    public string gender;
    private int age;

    public int Age
    {
        get => age;
        set
        {
            if(value<1||value>150)
            {
                age = 0;
            }
            else
            {
                age = value;
            }
        }
    }

    public Phone phone;

    public string GetInfo()
    {
        return $"姓名：{name}\n身份证：{id}\n性别：{gender}\n年龄：{age}\n手机型号：{phone.型号}\n手机号码：{phone.号码}";
    }

    public Students(string 姓名, string 身份证, string 手机型号, string 手机号码)
    {
        name = 姓名;
        id = 身份证;
        获取身份证信息();
        phone = new Phone(姓名, 手机型号, 手机号码);
    }

    // public (string 性别, int 年龄) 获取身份证信息()
    // {
    //     int 身份证倒数第2位 = id[16];
    //     gender = 身份证倒数第2位 % 2 == 0 ? "女" : "男";
    //     DateTime today = DateTime.Now;
    //     string year = id[6..10];
    //     string month = id[10..12];
    //     string day = id[12..14];
    //     DateTime birhday = DateTime.Parse($"{year}-{month}-{day}");
    //     int age = today.Year - birhday.Year;
    //     if (today.Month < birhday.Month) age--;
    //     if (today.Month == birhday.Month && today.Day > birhday.Day) age--;
    //     return (gender,age);
    // }
    public void 获取身份证信息()
    {
        int 身份证倒数第2位 = id[16];
        gender = 身份证倒数第2位 % 2 == 0 ? "女" : "男";
        DateTime today = DateTime.Now;
        string year = id[6..10];
        string month = id[10..12];
        string day = id[12..14];
        DateTime birhday = DateTime.Parse($"{year}/{month}/{day}");
        Age = today.Year - birhday.Year;
        if (today.Month < birhday.Month) Age--;
        if (today.Month == birhday.Month && today.Day > birhday.Day) Age--;
    }
}